/* 浏览器存储操作封装 */
class localStorageHelper {
  /*永久保存(普通)*/
  static setItem(key,value) {
    localStorage.setItem(key,JSON.stringify(value));
  }
  /*获取(普通)*/
  static getItem(key) {
    return JSON.parse(localStorage.getItem(key));
  }
  /*限时保存*/
	static setItemWithTime(key,value) {
    let curTime = new Date().getTime();
    localStorage.setItem(key,JSON.stringify({data:value,time:curTime}));
	}
  /*对限时保存的获取  exp:时效*/
	static getItemWithTime(key,exp=360000){
    let data = JSON.parse(localStorage.getItem(key));
    if (data==null) { console.log('data==null');return null;}
    let nowTime = new Date().getTime() - data.time;
    console.log('timer ++ '+nowTime);
    if (nowTime > exp) {
        localStorage.removeItem(key);
        return null;
    }else{
      let dataObjDatatoJson = data.data;
      return dataObjDatatoJson;
    }
  }
}

export default localStorageHelper;